package lion.blog.tag;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.SimpleTagSupport;

import lion.blog.model.BlogCatelog;
import lion.dev.lang.MapJ;
import lion.framework.core.web.path.PathVar;

/**
 * 博客页面路径 (面包屑)
 * 
 * @author lion
 * @email hl_0074@sina.com
 * @date 2015年12月3日
 */
public class BreadCrumbTag extends SimpleTagSupport {

	@Override
	public void doTag() throws JspException, IOException {

		StringBuilder builder = new StringBuilder();
		builder.append("当前位置:");

		PageContext context = (PageContext) this.getJspContext();
		HttpServletRequest hsr = (HttpServletRequest) context.getRequest();
		builder.append("<a href=\"/" + hsr.getContextPath() + "\">首页</a>");

		BlogCatelog catelog = (BlogCatelog) hsr.getAttribute("catelog");
		MapJ article = (MapJ) hsr.getAttribute("article");

		if (article != null) {
			catelog = article.getE("catelog");
		}

		if (catelog != null) {
			builder.append(" > <a href=\"/" + hsr.getContextPath() + "/" + PathVar.getVar("blog") + "/" + catelog.getCode() + "\">"
					+ catelog.getName() + "</a>");
			if (article == null) {
				builder.append(" > 文章");
			} else {
				builder.append(" > 正文");
			}
		} else {
			builder.append(" > 页面");
		}

		context.getOut().append(builder.toString());

		super.doTag();
	}

}
